package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import metier.Numero;
import metier.Spectacle;

public class DaoNumero 
{

	public static int AjoutNumero (Numero unNumero) throws ClassNotFoundException, SQLException
	{
		String chaine = "jdbc:mysql://localhost/";
		String req;
		Connection connec;
		connec = MySqlConnection.getConnection(chaine + "mlr1", "root", "");
		req = "insert into numero values (" + unNumero.getCodeNumero() + ", '" + unNumero.getLibNumero() + "')";
		System.out.println(req);
		return 1;
	}
	
	public static Vector <Numero> getLesNumeros () throws ClassNotFoundException, SQLException
	{
		String chaine = "jdbc:mysql://localhost/";
		Statement stLienBd = null;
		ResultSet res = null;
		String req;
		String req2;
		Connection connec;
		Vector <Numero> lesNumeros;
		Numero leNumero;
		connec = MySqlConnection.getConnection(chaine + "mlr1", "root", "");
		stLienBd = connec.createStatement();
		lesNumeros = new Vector <Numero>();
		try
		{
			
			req = "select * from numero";
			res = stLienBd.executeQuery(req);
			while (res.next())
			{
				leNumero = new Numero (res.getInt(1), res.getString(2));
				//A FAIRE : alimenter la porteuse CONTENIR
				lesNumeros.add(leNumero);
			}
			res.close();
			connec.close();
		}
		catch (Exception e)
		{
			System.out.println(e.getMessage());
		}
		return lesNumeros;
	}
}

